package com.efast.dmom.aps.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.dmom.aps.bean.ResultBean;
import com.efast.dmom.aps.bean.ShiftItem;
import com.efast.dmom.aps.entity.ShiftItemEntity;
import com.efast.dmom.aps.entity.SupplierEntity;
import com.efast.dmom.aps.entity.base.IModificationFlags;
import com.efast.dmom.aps.service.ShiftItemService;

@Controller
@RequestMapping(value = "/shiftItem")
public class ShiftItemController {
	@Autowired
	private ShiftItemService shiftItemService;
	
	
	@RequestMapping(value = "/operateByShiftItem")
	public @ResponseBody ResultBean operateByShiftItem(@RequestBody ShiftItem shiftItem) {
		// Determine the new
		ShiftItemEntity entity = shiftItem.getInnerEntity();

		if (entity.getModificationFlag() == IModificationFlags.NEW) {
			return shiftItemService.save(shiftItem);
			// Judge update
		} else if (entity.getModificationFlag() == IModificationFlags.MODIFIED) {
			return shiftItemService.update(shiftItem);
			// Judge to delete
		} else if (entity.getModificationFlag() == IModificationFlags.DELETED) {
			return shiftItemService.delete(shiftItem);
		}
		return null;
	}

	/*通过班次id查询班次详情信息*/
	@RequestMapping("/getShiftItemByShiftId")
	public @ResponseBody ResultBean getShiftItemByShiftId(@RequestBody long shiftId) {
		ResultBean result=new ResultBean(true,"");
		List<ShiftItem> list=shiftItemService.getShiftItemByShiftId(shiftId);
		result.setObject(list);
	    return result;
	}
	/*通过班次详情id查询班次详情信息*/
	@RequestMapping("/getById")
	public @ResponseBody ResultBean getById(@RequestBody long shiftId) {
		ResultBean result=new ResultBean(true,"");
		ShiftItem shiftItemInfo=shiftItemService.getById(shiftId);
		result.setObject(shiftItemInfo);         
	    return result;
	}
	
	@RequestMapping("/getShiftItem/{shiftId}")
	public @ResponseBody ResultBean getShiftItem(@PathVariable long shiftId) {
		ResultBean result=new ResultBean(true,"");
		List<ShiftItem> list=shiftItemService.getShiftItemByShiftId(shiftId);
		result.setObject(list);
	    return result;
	}
}